#include "ControlPanelClass.h"
#include "Bounce2.h"
#include "serlcd.h"

#ifndef ledb1
#include "constants.cpp"
#endif

ControlPanelClass::ControlPanelClass(void):LCD(lcd_pin)
{
	//Let the LCD warm up
	delay(500);
	// Setup LCD	
	LCD.setType(3);	
	LCD.clear();
	LCD.noCursor();
	LCD.setCursor(0,0);
	LCD.print("   Welcome to");
	LCD.setCursor(2,0);
	LCD.print("     ERRTT");
	LCD.setSplash();

	_ActiveScreen = &HomeScreen;
}

void ControlPanelClass::setup()
{
	isReady = false;
	// Most setup occurs after the main setup
}

void ControlPanelClass::update()
{
	if(isReady == false)
	{
		//These should only be updated during the loop phase
		SetActiveScreen(&HomeScreen);
		isReady = true;
	}
	
	_ActiveScreen->update();
}

void ControlPanelClass::SetActiveScreen(PanelMenuBaseClass * screen)
{
	_ActiveScreen = screen;
	_ActiveScreen->OnSetActive();
}

PanelMenuBaseClass * ControlPanelClass::GetActiveScreen()
{
	return _ActiveScreen;
}



ControlPanelClass::~ControlPanelClass(void)
{
}

bool ControlPanelClass::UpButtonPressed()
{
	return UpButton.read();
}

bool ControlPanelClass::LeftButtonPressed()
{
	LeftButton.update();
	return LeftButton.read() == LOW;
}

bool ControlPanelClass::MenuButtonPressed()
{
	MenuButton.update();
	return MenuButton.read() == LOW;
}

bool ControlPanelClass::DownButtonPressed()
{
	DownButton.update();
	return DownButton.read() == LOW;
}

bool ControlPanelClass::RightButtonPressed()
{
	RightButton.update();
		
	return RightButton.read() == LOW;
   
	
}

bool ControlPanelClass::EnterButtonPressed()
{	
	bool state = EnterButton.read();

	return enterButtonPreviousState && !state;
		
}


ControlPanelClass ControlPanel;